﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Xml;
using System.Text;
using Gift.WebApp;
using System.Collections;

using Gift.DAL;
using Gift.Model;

public partial class cn_promotion_goods_list : BasePage
{
    // Fields

    protected string cid = "00000000-0000-0000-0000-000000000000";

    protected string order = "proid";
    protected int ot = 1;
    protected int pageCount = 0;
    protected int pageIndex = 1;
    protected int pageSize = 20;
    protected PageList pl = new PageList();
    protected int total = 0;
    protected string xmlPath = "/cn/xml/promotion_goods_list.xml";

    // Methods
    protected StringBuilder CategoryBind()
    {
        StringBuilder builder = new StringBuilder();
        try
        {
            if (base.Request.QueryString["cid"] != null)
            {
                this.cid = base.Request.QueryString["cid"];
            }
            DataTable table = BaseFactory.theCategory.GetCategoryByParentIdAndCompanyIdAndIsShow("00000000-0000-0000-0000-000000000000", base.CompanyId, 1);
            builder.AppendLine("<div class=\"proclass\">");
            builder.AppendLine("<div class=\"classlist\">");
            builder.AppendLine("<ul>");
            builder.AppendLine("<li class=\"hoverli\"><strong>分类</strong>");
            foreach (DataRow row in table.Rows)
            {
                int num = BaseFactory.theCategory.GetCountByCaterotyAndIsShowAndisPromote(row["id"].ToString(), 1);
                builder.AppendLine(string.Concat(new object[] { "<a href=\"?cid=", row["id"], "\" ", (row["id"].ToString() == this.cid) ? "class='hovera'" : "", ">", row["categoryName"], "<span>(", num, ")</span></a>" }));
            }
            builder.AppendLine("</li>");
            builder.AppendLine("</ul>");
            builder.AppendLine("</div>");
            builder.AppendLine("<span class=\"clear\"></span>");
            builder.AppendLine("</div>");
        }
        catch
        {
        }
        return builder;
    }

    protected StringBuilder GoodsBind()
    {
        StringBuilder builder = new StringBuilder();
        try
        {
            if (base.Request.QueryString["cid"] != null)
            {
                this.cid = base.Request.QueryString["cid"];
            }
            if (base.Request.QueryString["p"] != null)
            {
                this.pageIndex = Convert.ToInt32(base.Request.QueryString["p"]);
            }
            this.pl.TblName = "db_shoppro";
            this.pl.StrGetFields = "proid,procode,proname,isNull(marketPrice,saleprice) as marketPrice,salePrice,probigpic,prosmallpic,proscore";
            this.pl.PageSize = this.pageSize;
            this.pl.PageIndex = this.pageIndex;
            this.pl.FldName = this.order;
            this.pl.DoCount = 1;
            this.pl.StrWhere = string.Format(" isPromotion=1 and (typeid = {0} or typeid in (select classId from db_productclass where parentId={0}) or typeid in (select classId from db_productClass where parentid in (select classId from db_productclass where parentId={0})))",this.cid) ;
            this.total = Convert.ToInt32(BaseFactory.thePageList.GetPageList(this.pl).Rows[0]["Total"]);
            this.pl.DoCount = 0;
            DataTable pageList = BaseFactory.thePageList.GetPageList(this.pl);
            builder.AppendLine("<div class=\"prolist salelist\">");
            builder.AppendLine("<ul>");
            foreach (DataRow row in pageList.Rows)
            {
                builder.AppendLine("<li>");
                builder.AppendLine(string.Concat(new object[] { "<strong class=\"sales\">促销商品</strong><a href=\"goods.html?id=", row["proid"], "\"><img src=\"", ServerImagePath + row["prosmallpic"], "\" alt=\"", row["proName"], "\" /></a>" }));
                builder.AppendLine(string.Concat(new object[] { "<p><a href=\"goods.html?id=", row["proid"], "\" title=\"", row["proName"], "\">", (row["proName"].ToString().Length > 12) ? (row["proName"].ToString().Substring(0, 12) + "...") : row["proName"], "</a><span>市场价", string.Format("{0:C}", Convert.ToDecimal(row["marketPrice"])), "</span><em>促销价：<strong>", string.Format("{0:C}", Convert.ToDecimal(row["salePrice"])), "</strong></em></p>" }));
                builder.AppendLine("</li>");
            }
            builder.AppendLine("</ul>");
            builder.AppendLine("<span class=\"clear\"></span>");
            builder.AppendLine(new PageListNo().FrontDeskDisplayPage(this.total, this.pageSize, this.pageIndex).ToString());
            builder.AppendLine("</div>");
        }
        catch
        {
        }
        return builder;
    }

    protected StringBuilder NewPromotionGoods()
    {
        StringBuilder builder = new StringBuilder();
        try
        {
            builder.AppendLine("<div class=\"sidebar sale_sider\">");
            builder.AppendLine("<div class=\"sidelist\">");
            builder.AppendLine("<h6><strong>最新促销商品</strong></h6>");
            builder.AppendLine("<ul>");
            DataTable table = BaseFactory.theGoods.GetGoodsByIsPromoteAndIsShelvesAndTop(1, 1, 5);
            foreach (DataRow row in table.Rows)
            {
                builder.AppendLine("<li>");
                builder.AppendLine(string.Concat(new object[] { "<a href=\"goods.html?id=", row["id"], "\"><img src=\"", row["thumbImg"], "\" alt=\"", row["imgAlt"], "\" /></a>" }));
                builder.AppendLine(string.Concat(new object[] { "<p><a href=\"goods.html?id=", row["id"], "\" title=\"", row["goodsName"], "\">", row["goodsName"], "</a><em>促销价：<strong>", string.Format("{0:C}", Convert.ToDecimal(row["salePrice"])), "</strong></em><span>已有<strong>", row["scoreNumber"], "</strong>人评分</span></p>" }));
                builder.AppendLine("</li>");
            }
            builder.AppendLine("</ul>");
            builder.AppendLine("<span class=\"clear\"></span>");
            builder.AppendLine("</div>");
            XmlDocument document = new XmlDocument();
            document.Load(base.Server.MapPath(this.xmlPath));
            XmlNodeList childNodes = document.SelectSingleNode("promotion_goods_list_ad/right").ChildNodes;
            foreach (XmlNode node in childNodes)
            {
                XmlElement element = (XmlElement)node;
                builder.AppendLine("<a href=\"" + element.GetAttribute("url") + "\"><img src=\"" + element.GetAttribute("src") + "\" alt=\"" + element.GetAttribute("alt") + "\" /></a>");
            }
            builder.AppendLine("</div>");
        }
        catch
        {
        }
        return builder;
    }

    protected void Page_Load(object sender, EventArgs e)
    {
    }

}